package com.k8.common.ioc.injectorImpl;

import com.k8.common.factroy.BeanInfo;
import com.k8.common.factroy.instance.BeanInstanceException;
import com.k8.common.factroy.instance.InstanceStrategyFactory;
import com.k8.common.ioc.Injector;

import java.util.Map;
import java.util.Set;

public abstract class AbstractInstanceStrategyFactoryInjector implements Injector {

    protected void synJudge0(Map<String, Object> relyBeanNames, InstanceStrategyFactory instanceStrategyFactory) {
        Set<String> names = relyBeanNames.keySet();
        for (String name : names) {
            Object instance = relyBeanNames.get(name);
            BeanInfo beanInfo = instanceStrategyFactory.getBeanInfo(name);
            if (beanInfo != null) {
                Object value = beanInfo.getValue();
                if (value != null) {
                    if (value == instance) {
                        int state = beanInfo.getState().get();
                        while (state < 3) {
                            state = beanInfo.getState().get();
                            if (state == -1)
                                throw new BeanInstanceException("Rely bean instance error, class: " + beanInfo.getType().getName());
                        }
                    }
                }
            }
        }
    }

    @Override
    public <T> T getAdaptive(Map<String, SafeObjectHolder> relyBeanMaps, Class<T> clazz) {
        return null;
    }

}
